package com.lkd.handler;

import cn.hutool.json.JSONUtil;
import com.lkd.config.TopicConfig;
import com.lkd.contract.VendoutContract;
import com.lkd.emq.annotation.Topic;
import com.lkd.emq.handler.MsgHandler;
import com.lkd.service.VendingMachineService;
import lombok.extern.slf4j.Slf4j;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.IOException;

@Slf4j
@Component
@Topic(TopicConfig.VMS_VENDOUT_TOPIC)
public class VendoutMsgHandler implements MsgHandler {


    @Autowired
    private VendingMachineService vmService;

    @Override
    public void process(String jsonMsg) throws IOException {
        log.info("售货机微服务接收出货消息: {}",jsonMsg);
        VendoutContract vendoutContract = JSONUtil.toBean(jsonMsg, VendoutContract.class);

        //调用service处理业务
        Boolean isSucess = vmService.vendout(vendoutContract);
        if(isSucess==false){
            //出货失败，退款操作
            log.info("执行退款操作....");
        }

    }
}